package com.bawei.library_common

import android.app.Application
import android.os.Build
import com.bawei.library_base.BaseApplication
import com.bawei.library_mvi.loadsirr.*
import com.bawei.library_common.websocket.WebSocketUtils
import com.kingja.loadsir.core.LoadSir

/**
 * @Author : 
 * @Time : On 2023/6/20 11:24
 * @Description : BaseApplication
 */
open class CommonApplication:BaseApplication(){
    override fun onCreate() {
        super.onCreate()
        initLoadSir()
    }

    private fun initLoadSir() {
        //loadSir初始化
        LoadSir.beginBuilder()
            .addCallback(ErrorCallback()) //失败
            .addCallback(EmptyCallBack()) //空
            .addCallback(LoadingCallback()) //加载中
            .addCallback(TimeoutCallback()) //链接超时
            .addCallback(LottieLoadingCallback())//动画加载中
            .setDefaultCallback(LottieLoadingCallback::class.java) //设置默认状态页
            .commit()
    }

    companion object{

         //所有业务模块均可访问
         lateinit var socketUtils:WebSocketUtils
         fun getWebSocket(websocket_url:String,listener:WebSocketUtils.ReceiveMsgListener):WebSocketUtils{
             socketUtils = WebSocketUtils.Builder()
                 .setListener(listener)
                 .build()
             return socketUtils

         }



    }


    //返回版本号

    fun getAppVersionCode():Long{
        return if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){//安卓9。0
            packageManager.getPackageInfo(packageName, 0).longVersionCode.toLong()
        }else{
            packageManager.getPackageInfo(packageName, 0).versionCode.toLong()

        }
    }
    //返回版本名称
    fun getAppVersionName():String{
        return packageManager.getPackageInfo(packageName, 0).versionName
    }

}
